Skip to content

Index class-likes declared inside conditional blocks#154

Merged
AJenbo merged 3 commits into
PHPantom-dev:mainfrom
MrSrsen:fix/conditional-class-indexing
Jun 20, 2026
Merged

Index class-likes declared inside conditional blocks#154
AJenbo merged 3 commits into
PHPantom-dev:mainfrom
MrSrsen:fix/conditional-class-indexing

Conversation

@MrSrsen

@MrSrsen MrSrsen commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

Fixes: #153

A named class/interface/trait/enum declared inside an if/else (or try/ switch/loop) block — e.g. Doctrine's ServiceEntityRepository, defined per ORM version inside an 'if (! property_exists(...))' guard — was discovered by name only: its parent and @extends/@template-extends generics were dropped, so the inheritance/generic chain collapsed ($repo->find() resolved to object/mixed instead of the entity).

Descend into container-statement bodies when extracting class-likes (parser/classes.rs), route top-level containers through the extractor (parser/mod.rs, parser/ast_update.rs), and keep the first declaration when the same FQN appears in multiple branches (first-occurrence-wins, matching PHPStan/Psalm and the existing classmap convention).

Adds unit tests + an assert_type regression fixture.

A named class/interface/trait/enum declared inside an if/else (or try/
switch/loop) block — e.g. Doctrine's ServiceEntityRepository, defined per
ORM version inside an 'if (! property_exists(...))' guard — was discovered
by name only: its parent and @extends/@template-extends generics were
dropped, so the inheritance/generic chain collapsed ($repo->find() resolved
to object/mixed instead of the entity).

Descend into container-statement bodies when extracting class-likes
(parser/classes.rs), route top-level containers through the extractor
(parser/mod.rs, parser/ast_update.rs), and keep the first declaration when
the same FQN appears in multiple branches (first-occurrence-wins, matching
PHPStan/Psalm and the existing classmap convention).

Adds unit tests + an assert_type regression fixture.
@codecov-commenter

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

AJenbo
AJenbo previously approved these changes Jun 20, 2026
@AJenbo AJenbo enabled auto-merge (squash) June 20, 2026 13:45
@AJenbo AJenbo disabled auto-merge June 20, 2026 13:45
@AJenbo AJenbo merged commit f7f7b0b into PHPantom-dev:main Jun 20, 2026
7 checks passed
@AJenbo

AJenbo commented Jun 20, 2026

Copy link
Copy Markdown
Collaborator

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Classes declared inside conditional blocks (if/else) are not indexed for type resolution — breaks Doctrine ServiceEntityRepository generic chain

3 participants